using System.Collections.Generic;
using System.Linq;
using TeamCityMonitor.Models;
using TeamCityMonitor.Repository;

namespace TeamCityMonitor.Manager.CustomCreators
{
    public class QuoteCreator : ICustomModelCreator
    {
        private readonly IQuoteRepository _quoteRepository;

        public QuoteCreator(IQuoteRepository quoteRepository)
        {
            _quoteRepository = quoteRepository;
        }

        public bool IsActive()
        {
            return Properties.Settings.Default.ShowQuotes;
        }

        public List<CustomModel> GetCustomModels()
        {
            var quotes = _quoteRepository.GetAllQuotes();

            var models = new List<CustomModel>();
            quotes.ToList().ForEach(quote => models.Add(new CustomModel
                                                            {
                                                                Title = quote.Title,
                                                                ImageUrl = (quote.ImageUrl ?? "../../Content/quote.png"),
                                                                Footer = string.Format("\"{0}\"",quote.Text),
                                                                Signature = quote.Signature
                                                            }));
            return models;
        }
    }
}